package bdd.sql.server.bean;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Bean ServerStorage
 * @author Guillaume Pocas & Jean-Fraçois Augé
 */
@Entity
@Table(name = "kraken_server_storage")
public class ServerStorage {
	
	@Id
	@GeneratedValue
	@Column(name = "storserv_id")
	private int storserv_id;
	
	@Column(name = "storserv_name", nullable = false, updatable = false, unique = true)
	private String storserv_name;
	
	@Column(name = "storserv_ip_adress", nullable = false, updatable = false, unique = true)
	private String storserv_ip;
	
	@Column(name = "storserv_cluster_name", nullable = false, updatable = false, unique = true)
	private String storserv_cluster;
	
	@OneToMany(mappedBy="storage")
    private Set<Video> videos;
	
	@OneToOne(mappedBy = "storage")
	private Keystore keystore;
	
	@OneToOne
	@JoinColumn(name = "storserv_site", nullable = true, updatable = true, unique = true)
	private ServerSite site;
	
	@OneToOne
	@JoinColumn(name = "storserv_central", nullable = true, updatable = true, unique = true)
	private ServerCentral central;

	@ManyToOne(cascade = {CascadeType.ALL})
    @JoinColumn(name = "id_conf")
	private Configuration storage_conf;
	
	/**
	 * Constructeur vide.
	 */
	public ServerStorage(){	}
	
	/**
	 * Créer un nouveau StorageServer.
	 * @param name
	 * @param ip
	 * @param cluster
	 * @param totalSpace
	 * @param freeSpace
	 */
	public ServerStorage(String name, String ip, String cluster){
		this.storserv_name = name;
		this.storserv_ip = ip;
		this.storserv_cluster = cluster;
	}

	public int getStorserv_id() { return storserv_id;	}
	public void setStorserv_id(int storserv_id) { this.storserv_id = storserv_id;	}

	public String getStorserv_name() { return storserv_name;	}
	public void setStorserv_name(String storserv_name) { this.storserv_name = storserv_name;	}

	public String getStorserv_ip() { return storserv_ip;	}
	public void setStorserv_ip(String storserv_ip) { this.storserv_ip = storserv_ip;	}

	public String getStorserv_cluster() { return storserv_cluster;	}
	public void setStorserv_cluster(String storserv_cluster) { this.storserv_cluster = storserv_cluster;	}
	
	public Set<Video> getVideos() { return videos; }
	public void setVideos(Set<Video> videos) { this.videos = videos; }
	
	public Keystore getKeystore() {	return keystore;	}
	public void setKeystore(Keystore keystore) {	this.keystore = keystore;	}
	
	public ServerSite getSite() {	return site;	}
	public void setSite(ServerSite site) {	this.site = site;	}

	public ServerCentral getCentral() {	return central;	}
	public void setCentral(ServerCentral central) {	this.central = central;	}
	
	public Configuration getConf() { return storage_conf; }
	public void setConf(Configuration storage_conf) { this.storage_conf = storage_conf; }

	@Override
	public String toString() { return getStorserv_name(); }

}
